<?php

class Core_Backend_Component_Global_View_Module_Assign extends Core_Backend_Share_View_Form {

    protected function buildNavigation($navigation) {
        $navigation->addLabel($this->__f('global.title.module_assign', $this->getModel()->getName()));
        parent::buildNavigation($navigation);
    }
    protected function buildToolbar($toolbar) {
    	$group = $toolbar->createGroup('back');
        $group->addLink($this->getHistoryUrl('global/module/index'), $this->__('share.button.back'));
        $group = $toolbar->createGroup('save');
        $group->addButton($this->__('share.button.save'))
        	  ->bindEvent('click', "Kdf.Ui.getForm('".$this->getForm()->getId()."').submit('".$this->getUrl(NULL, 'save')."')");
        parent::buildToolBar($toolbar);    	
    }
    protected function buildForm($form) {
        $entity = $this->getModel();
        $form->setAction($this->getUrl())
                ->setId('assign_form')
                ->addHiddenField('id', 'assign[id]', $this->getModel()->getId());
        $form->addSelectField($this->__('share.label.area'), 'area_id', 'assign[area_ids][]')
                ->bindData($this->getAreas(), 'name', 'id')
                ->setMultiple(TRUE)
                ->setSize(10)
                ->setValue($this->getModel()->getAssignedAreas()->getItemPropertyValue('id'));
//        $arr = array();
//        foreach ($this->getAreas() as $area) {
//            $form->addSelectField($area['name'], 'area' . $area['area_id'], 'assign[' .$area['id']. '][]')
//                    ->bindData($value, 'name', 'id')
//                    ->setMultiple(TRUE)
//                    ->setSize(5);
//            if (!array_key_exists($area->getWebsiteId(), $arr)) {
//                $arr[$area->getWebsiteId()] = array();
//            }
//            $arr[$area->getWebsiteId()][] = $area;
//        }
//        foreach ($arr as $index => $value) {
//            $form->addSelectField($value[0]['website_name'], 'website' . $value[0]['website_id'], 'assign[website' .$value[0]['id']. '][]')
//                    ->bindData($value, 'name', 'id')
//                    ->setMultiple(TRUE)
//                    ->setSize(5);
//        }
         parent::buildForm($form);
    }

}

